<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="" method="post">
		<table border="1" cellspacing="0" cellpadding="10" id="stuTable">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭住址</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="inputname1" id="inputId1" value="10"></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id=""></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id=""></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id=""></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id=""></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
		</table>
		</form>
			<input type="checkbox" name="" id="checkall1" value="" onclick="dosell1()" />全选
			<input type="checkbox" name="" id="checkall2" value="" onclick="dosell2()" />全选男
			<input type="checkbox" name="" id="checkall3" value="" onclick="dosell3()" />全选女
	</body>
	<script type="text/javascript">
			function dosell1()
			{
				var tableobj = document.getElementById('stuTable');
				var inputAll = tableobj.getElementsByTagName('input');
				console.log(inputAll);
				var checkedAll = document.getElementById('checkall1').checked;
				console.log(checkedAll);
				for(var i=0;i<inputAll.length;i++){
					inputAll[i].checked = checkedAll;
				}
			}
			function dosell2(){
				var stu_man = document.getElementsByClassName('sex');
				for(var i=0;i<stu_man.length;i++){
				if(stu_man[i].innerText =='男'){
					var tableobj = document.getElementById('stuTable');
					var inputAll = tableobj.getElementsByTagName('input');
					var checkedAll = document.getElementById('checkall2').checked;
					inputAll[i].checked = checkedAll;
				}
				}
			}
			function dosell3(){
				var stu_woman = document.getElementsByClassName('sex');
				for(var i=0;i<stu_woman.length;i++){
				if(stu_woman[i].innerText =='女'){
					var tableobj = document.getElementById('stuTable');
					var inputAll = tableobj.getElementsByTagName('input');
					var checkedAll = document.getElementById('checkall3').checked;
					inputAll[i].checked = checkedAll;
				}
				}
			}
	</script>
</html>
